package com.potenza.wxuser.service;

import com.potenza.wxuser.mapper.WeixinUserMapper;
import com.potenza.wxuser.model.WeixinUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.concurrent.Future;

@Service
public class WxMiniService {

    public WeixinUser findByOpenid(String openid){
        return null;
    }

    public void save(WeixinUser weixinUser) {
        WeixinUser weixinUser1 = findByOpenid(weixinUser.getOpenid());
        if(weixinUser1!=null){
            BeanUtils.copyProperties(weixinUser,weixinUser1);
            weixinUser1.setUpdateTime(new Date());
            //weixinUserMapper.updateById(weixinUser1);
        }else{
            weixinUser.setCreateTime(new Date());
            weixinUser.setUpdateTime(new Date());
            //weixinUserMapper.insert(weixinUser);
        }
    }

    public void update(WeixinUser weixinUser) {

        //weixinUserMapper.updateById(weixinUser);
    }

    /**
     * 只能返回void 或者Future
     */
    @Async("asyncServiceExecutor")
    public Future<String> waterMarkAndOss(String params) throws InterruptedException {
        //加水印
        //OSS 上传
        System.out.println("水印线程:" + Thread.currentThread().getName());

        Thread.sleep(5000);



        return new AsyncResult<String>("oss_url");
    }

    public static void main(String[] args) {
        BigDecimal decimal = new BigDecimal("1000");
        BigDecimal divide = decimal.divide(new BigDecimal("10"));
        System.out.println(divide);
    }
}
